package com.hmy.finance.manager.crm;

import com.hmy.ccp.common.result.FeignResult;
import com.hmy.ccp.error.exception.HMYRuntimeException;
import com.hmy.crm.api.bo.response.OpportunityFeignInfoResponse;
import com.hmy.crm.api.client.OpportunityFeignClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 调用crm服务的商机feign接口的客户端
 *
 * @author songkf
 * @version 1.0.0
 * @since 1.0.0
 */

@Slf4j
@Component
public class OpportunityFeignClientRpc {
    @Resource
    private OpportunityFeignClient opportunityFeignClient;

    /**
     * 根据商机ID查询商机信息以及关联的项目、客户信息
     *
     * @param opportunityId 商机ID
     * @return {@link OpportunityFeignInfoResponse}商机信息以及关联的项目、客户信息
     * @author songkf
     */
    public OpportunityFeignInfoResponse opportunityInfo(Long opportunityId) {
        log.info("opportunityFeignClient.opportunityInfo params:{}", opportunityId);
        FeignResult<OpportunityFeignInfoResponse> response;
        try {
            response = opportunityFeignClient.opportunityInfo(opportunityId);
            log.info("opportunityFeignClient.opportunityInfo response:{}", response);
        } catch (Exception e) {
            log.error("调用HMY-CRM服务的查询商机信息接口异常，商机ID：{}", opportunityId, e);
            throw new HMYRuntimeException(5005001, "调用HMY-CRM服务的查询商机信息接口异常");
        }
        return response.getData();
    }


}
